package com.train.member.mapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.train.member.dto.SmsRecordDTO;
import com.train.member.po.SmsRecordPO;
import com.train.mybatis.base.MyBaseMapper;

/**
* @author baitiaojun
* @description 针对表【sms_record】的数据库操作Mapper
* @createDate 2025-02-10 01:55:15
* @Entity generator.domain.SmsRecord
*/
public interface SmsRecordMapper extends MyBaseMapper<SmsRecordPO> {

    default boolean saveOne(SmsRecordDTO smsRecordDTO) {
        SmsRecordPO smsRecordPO = BeanUtil.copyProperties(smsRecordDTO, SmsRecordPO.class);
        return this.insert(smsRecordPO) > 0;
    }

    /**
     * 查询短信记录数量
     * @param smsRecordDTO
     * @return
     */
    default Long querySmsRecord(SmsRecordDTO smsRecordDTO) {
        LambdaQueryWrapper<SmsRecordPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SmsRecordPO::getMobile, smsRecordDTO.getMobile());
        queryWrapper.eq(SmsRecordPO::getBusinessType, smsRecordDTO.getBusinessType());
        queryWrapper.between(SmsRecordPO::getSendTime, smsRecordDTO.getBefore(), smsRecordDTO.getNow());
        return this.selectCount(queryWrapper);
    }

    default boolean editSmsRecord(SmsRecordDTO smsRecordDTO) {
        LambdaUpdateWrapper<SmsRecordPO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(SmsRecordPO::getIsUse, smsRecordDTO.getIsUsed())
                .set(SmsRecordPO::getUseTime, smsRecordDTO.getUseTime())
                .eq(SmsRecordPO::getMobile, smsRecordDTO.getMobile())
                .eq(SmsRecordPO::getSmsCode, smsRecordDTO.getSmsCode());
        return this.update(updateWrapper) > 0;
    }
}




